﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GA.Server.ApiInfo;
using System.Xml;

namespace GA.Server.Api
{
    public class ApiInfoGetAgencyInfo : SignedApiCall
    {
        public IEnumerable<ApiPlayer> Players { get; private set; }

        public ApiInfoGetAgencyInfo()
        {
        }

        public ApiInfoGetAgencyInfo(int clientId, string authorizationText, string sessionId)
            : base(clientId, authorizationText, sessionId)
        {
        }

        public void LoadApi(int agencyId)
        {
            LoadSignedApiCall("agencyId=" + agencyId.ToString());

            XmlNodeList playerNodes = XmlDocument.GetElementsByTagName("a:get_agency_detailsResult");
            List<ApiPlayer> players = new List<ApiPlayer>();
            foreach (XmlNode playerNode in playerNodes)
            {
                players.Add(new ApiPlayer(playerNode.CreateNavigator().ReadSubtree()));
            }
            Players = players;
        }

        protected override string ApiCallName
        {
            get { return "GetAgencyInfo"; }
        }
    }
}
